import { defineStore } from "pinia";
import { bannerList,deleteBanner,addBanner,updateFlag } from '../API/banner'

export const useBanner = defineStore('useBannerStore',{
    state:() => {
        return {
            banlist:[],
            flag:false,
            img:[]
        }
    },
    getters:{

    },
    actions:{
        // 获取轮播图列表
        async handleBanner() {
            const res = await bannerList()
            console.log(res);
            if(res.code === '200') {
                this.banlist = res.data
            }
        },
        // 删除单条
        async handleDel(id) {
            await deleteBanner(id)
            console.log('删除成功');
            this.handleBanner()
        },

        // 添加轮播图
        async handleAdd(form) {
            await addBanner(form)
            this.handleBanner()
        },

        //访问状态
        async handleFlag(id,flag) {
            await updateFlag(id,flag)
            this.handleBanner()
        }
    }
})